package com.tff.gmall.manger.controller;

import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;

import java.io.IOException;

public class TestMain {

    //String  confPaht = this.getClass().getResource("/tracker.conf").getPath();

    public static void main(String[] args) throws IOException, MyException {
        //参考这篇文章解决读取配置文件出错问题
        //https://blog.csdn.net/qq_45337887/article/details/107837086

        //获取tracker的配置文件
        String confPaht = TestMain.class.getResource("/tracker.conf").getPath();
        //对获取到的配置文件路径进行一次解码
        confPaht = java.net.URLDecoder.decode(confPaht, "utf-8");

        ClientGlobal.init(confPaht);

        TrackerClient trackerClient = new TrackerClient();

        //获得trackerServer的示例
        TrackerServer trackerServer = trackerClient.getTrackerServer();
        //获得storageClient实例，这个实例就可以用来上传文件
        StorageClient storageClient = new StorageClient(trackerServer, null);

        String[] paths = storageClient.upload_file("d:/555.jpg", "jpg", null);

        for (String p : paths) {
            System.out.println(p);
        }
    }
}
